<script type="text/javascript">document.title="<?=$page_title?> - <?=$GLOBALS['web_title']?>";</script>
<link rel="stylesheet" type="text/css" href="css/c_common.css">
<link rel="stylesheet" type="text/css" href="css/prodlist.css">
<link rel="stylesheet" type="text/css" href="css/easydialog.css"/>
<link rel="stylesheet" type="text/css" href="css/page.css">
<link rel="stylesheet" type="text/css" href="css/my_buttons.css">
<div class="clay" id="prod_list">
<div class="content">
<h3 class="mc_title">
    <span class="mctit_1"><span class="mctit_2"><?=$page_title?></span></span>
    <?if($_SESSION['com_type']!=='景区' && $status!==2):?>
    <span class="mctit_1 mctit_3"><a href="prod_sale.html" class="mctit_2 mctit_4">转分销产品</a></span>
    <?endif;?>
</h3>
<form class="search_form" id="search_form" action="<?=$_SERVER['PHP_SELF'];?>" method="get">
    <table class="search_tbl">
        <?php if($_SESSION['memberID']==1):?>
        <link href="js/plugin/jq/jquery-ui.min.css" rel="stylesheet">
        <tr>
            <th>供应商：</th>
            <td>
                <select class="fenxiaoSelect controls" name="supplier" id="">
                    <option value="">请选择供应商</option>
                    <?foreach($DistorsNames as $key=> $cn):?>
                    <option value="<?=$key?>" <?if($_REQUEST['supplier']==$key)echo 'selected="selected"'?>><?=$cn?></option>
                    <?endforeach;?>
                </select>
                <input name="apply_did" type="hidden" value="<?=$_GET['apply_did']?>"/>
                地区：<span id="area"></span>
                <input name="area" type="hidden" value="<?=$_GET['d_province'].'|'.$_GET['d_city']?>"/>
            </td>
        </tr>
        <script src="js/plugin/jq/jquery-ui-1.10.4.min.js"></script>
        <script>
            (function(){
                $("input[name='s_app_name']").autocomplete({
                    source: function( request, response ) {
                        $.getJSON( "call/jh_mem.php", {
                            action: 'SearchProviders',
                            dname: extractLast( request.term )
                        }, response );
                    },
                    minLength: 2,
                    select: function( event, ui ) {
                        $(this).next('input:hidden').val(ui.item.id);
                    }
                });
            })();
        </script>
        <?php else:?>
        <tr>
            <th>地区：</th>
            <td>
                <span id="area"></span>
                <input name="area" type="hidden" value="<?=$_GET['d_province'].'|'.$_GET['d_city']?>"/>
            </td>
        </tr>
        <?php endif;?>
        <script src="js/jquery.getareas.js" type="text/javascript"></script>
        <script>
            function split( val ) {
                return val.split( /,\s*/ );
            }
            function extractLast( term ) {
                return split( term ).pop();
            }
            $(document).ready(function(){
                if($("#area").length){
                    var area,pro_id, city_id,countr_id;
                    if($("input[name='area']").val()){
                        area = $("input[name='area']").val().split('|'),
                                por_id = area[0],city_id = area[1],country_id = area[2];
                    }
                    var areaParam = {
                        update:true,
                        pro_id:por_id,
                        city_id:city_id,
                        county_id:country_id,
                        depth:2
                    };
                    $("#area").getAreas(areaParam);
                }
                $("input[name='s_app_name']").on('keyup', function(){
                    if ($(this).val().length==0) {
                        $(this).next('input:hidden').val('');
                    }
                })
            });
        </script>
        <tr>
            <th>产品名称：</th>
            <td>
                <input type="text" class="input-txt w300" title="请输入产品名称或产品ID或6位数产品编号" placeholder="请输入产品名称或产品ID或6位数产品编号" name="s_title" value="<?=$_GET['s_title']?>" maxlength="30"/>
                <a href="javascript:" class="search_btn" onclick="$('form#search_form').submit()">搜　索</a>
                <?if($_SESSION['dtype']==9):?>
                <a href="prodlists_load.html?status=<?=$status?>" target="_blank" class="search_btn" style="background:#2686e6;">导　出</a> 
                <?endif;?>
                <a href="javascript:" class="more">更多筛选条件 <i class="arrow">&nbsp;</i></a>
            </td>
        </tr>
        <tr  class="more hidden">
            <th>产品类型：</th>
            <td>
                <select name="p_type">
                    <option value="">不限</option>
                    <option value="A">景点</option>
                    <option value="B">线路</option>
                    <option value="C">酒店</option>
                    <option value="F">套票</option>
                </select>
                        <span class="s_title" style="margin:0 10px 0 9px">
                            终端号：<input type="text" class="input-txt w60" value="<?=$_GET['terminal']?>" name="terminal"/>
                        </span>
            </td>
        </tr>
    </table>
</form>
<div class="boxs">
    <?php if(!$data['total']):?>
    <div class="box noresult">您还未发布任何产品，赶快去<a href="prod_type.html">发布</a>吧！</div>
    <?php return;?>
    <?php endif;?>
    <?php foreach($data['lands'] as $prod):?>
    <?php
                    $areaHtml = '';
                    if(!empty($prod['area'])) {
                        list($prov, $city) = explode('|', $prod['area']);
                        $areaHtml = '<span class="area">['.$areas[$prov].' '.$areas[$city].']</span>';
    }
    ?>
    <div class="box" id="box_<?=$prod['id']?>">
        <?if($status==2 && array_key_exists('S:'.$prod['id'],$packageMsg)):?>
        <p style="color:red;margin:10px 10px 0;">
            <? echo $packageMsg['S:'.$prod['id']]['timer'],'  ',$packageMsg['S:'.$prod['id']]['message'];?>
        </p>
        <?endif;?>
        <?php if($status!=1):?>
        <div class="rm" data-sid="<?=$prod['id']?>">
            <a class="set_ls" href="javascript:" data-state="3" title="删除该产品及所有票类">&nbsp;</a>
        </div>
        <?php endif;?>
        <div class="imgDiv">
            <a><img class="small" src="<?=$prod['imgpath']?>"></a>
            <div class="bigpic none"><img class="normal" src="<?=$prod['imgpath']?>" style="width: 0px; display: inline-block;"></div>
        </div>
        <div class="linfo">
            <p class="list">
                <?=$areaHtml?><?=!empty($prod['jtype'])?"<span>{$prod['jtype']}</span>":''?><span>终端号：<?=$prod['terminal']?></span>
            </p>
            <p class="title">
                <a href="scenicDetail.html?lid=<?=$prod['id']?>" target="_blank"><?=$prod['title']?></a>
                <span class="normal_font">(ID:<?=$prod['salerid']?>)</span>
            </p>
            <p class="dname">
                供应商：<?=$memberNames[$prod['apply_did']]?>
            </p>
            <p class="address">地址：<?=$prod['address']?></p>
        </div>

        <div class="oprate">
            <?php $c_t = count($data['tickets'][$prod['id']]);?>
            <?php if($prod['sync_status']==2):?>
            同步产品禁止操作
            <?php else:?>
            <p data-sid="<?=$prod['id']?>">
                <?if($prod['status']==1):?>
                <a class="set_ls lnk mmxj" href="javascript:" data-state="2" data-type="<?=$prod['p_type']?>">&nbsp;</a>
                <? else :?>
                <a class="set_ls lnk mmsj" href="javascript:" data-state="1" data-type="<?=$prod['p_type']?>">&nbsp;</a>
                <?endif;?>
                <a class="lnk mmxg" href="prod_edits.html?sid=<?=$prod['id']?>" target="_blank">&nbsp;</a>
            </p>
            <p >
                <?if($prod['p_type']=='F'):?>
                <?if($c_t)://套票门票数量判断?>
                <!--<a class="lnk lnk_l mmtj" href="javascript:alert('套票只能有一张门票');" target="_blank">&nbsp;</a>-->
                <?else:?>
                <a class="lnk lnk_l mmtj" href="product_publish_tar.html?sid=<?=$prod['id']?>" target="_blank">&nbsp;</a>
                <?endif;//套票门票数量判断结束?>
                <?else:?>
                <a class="lnk lnk_l mmtj" href="product_publish.html?sid=<?=$prod['id']?>" target="_blank">&nbsp;</a>
                <?endif;?>
            </p>
            <p >
                <a class="lnk lnk_l mmyz" href="terminal_chk.html?sid=<?=$prod['id']?>" target="_blank">&nbsp;</a>
            </p>
            <?php endif;?>
        </div>

        <div class="detail">
            <p>
                        <span class="dollar"><i>¥</i>
                        <strong><?=is_array($data['tickets'][$prod['id']]) ? min_by_key($data['tickets'][$prod['id']],'fprice') : 0;?></strong></span>起
            </p>
            <p><a href="scenicDetail.html?lid=<?=$prod['id']?>" target="_blank">散客预定</a></p>
            <?php if($prod['sync_status']==2):?>
            <p><a class="sync" data-action="cancel_sync_land" data-lid="<?=$prod['id']?>" href="javascript:;" >取消同步</a></p>
            <?php endif;?>
        </div>
        <table class="ticket_list">
            <thead>
            <tr>
                <th class="id">产品ID</th>
                <th class="title">票名称</th>
                <th class="price">供货价</th>
                <th class="price">建议零售价</th>
                <th class="price">门市价</th>
                <th class="craettime">创建时间</th>
                <th class="storage">库存</th>
                <th class="sale">销量</th>
                <th>销售范围</th>
                <th>状态</th>
                <th class="operate">操作</th>
            </tr>
            </thead>
            <tbody>
            <?php if(!$c_t): ?>
            <tr><td colspan="11">未添加票类或已下架</td></tr>
            <?php else:?>
            <?php foreach($data['tickets'][$prod['id']] as $key => $ticket):?>
            <?php
                                $class = '';
                                if($c_t==($key+1)) {
                                    $class = 'last';
                                }
                                if($key>5) {
            $class .= ' hidden more';
            }
            ?>
            <tr data-land="<?=$ticket['landid']?>" class="<?=$class?>" id="tr_<?=$ticket['pid']?>">
                <td title="供应商aid|景区lid|门票tid" class="id" data-tid="<?=$ticket['id']?>"><?=$prod['apply_did']?>|<?=$prod['id']?>|<?=$ticket['id']?></td>
                <?if($prod['p_type']=='F'):?>
                <td data-pid="<?=$ticket['pid']?>" class="title" title="<?=$ticket['title']?>"><a href="ticket_edit_tar.html?sid=<?=$prod['id']?>&prod_id=<?=$ticket['id']?>" target="_blank"><?=mb_substr($ticket['title'],0, 10,'utf-8')?></a></td>
                <?else:?>
                <td data-pid="<?=$ticket['pid']?>" class="title" title="<?=$ticket['title']?>"><a href="ticket_edit.html?sid=<?=$prod['id']?>&prod_id=<?=$ticket['id']?>" target="_blank"><?=mb_substr($ticket['title'],0, 10,'utf-8')?></a></td>
                <?endif;?>
                <td class="price"><strong><?=(is_numeric($ticket['fprice'])?'<i class="dollar">¥</i>':'').$ticket['fprice'];?></strong></td>
                <td class="price lprice"><?=(is_numeric($ticket['uprice'])?'<i class="dollar">¥</i>':'').$ticket['uprice'];?></td>
                <td class="price tprice"><i class="dollar">¥</i><?=$ticket['tprice']?></td>
                <td class="create_time" title="<?=$ticket['verify_time']?>"><?=substr($ticket['verify_time'],0,10)?></td>
                <td class="storage"><?=$ticket['storage']==-1? '不限' : $ticket['storage']; ?></td>
                <td class="sale"><a href="javascript:;" class="wSales">查看</a></td>
                <td class="p2l"><?=$P2L[$ticket['p_status']]?></td>
                <td class="vst"><?=$ProdState[$ticket['apply_limit']]?></td>
                <td class="operate">
                    <a href="adjusting.html?pid=<?=$ticket['pid']?>" target="_blank">分销价格</a>
                    <?php if($ticket['sync_status']!=2):?>
                    <a href="storageConfig.html?pid=<?=$ticket['pid']?>" target="_blank">库存</a>
                    <?php if($ticket['apply_limit']==2):?>
                    <a href="javascript:;" class="set_state" data-state="1" data-pid="<?=$ticket['pid']?>">上架</a>
                    <?php else:?>
                    <a href="javascript:;" class="set_state" data-state="2" data-pid="<?=$ticket['pid']?>">下架</a>
                    <?php endif;?>
                    <a href="javascript:;" class="set_state" data-state="6" data-pid="<?=$ticket['pid']?>">删除</a>
                    <?php endif;?>
                </td>
            </tr>
            <?php endforeach; ?>
            <?php if($key>5):?>
            <tr class="showMore"><td colspan="12"><a href="javascript:;" class="more">查看所有票类 <i class="arrow">&nbsp;</i></a></td></tr>
            <?php endif;?>
            <?php endif;?>
            </tbody>
        </table>
    </div>
    <?php endforeach; ?>
    <?php page($data['total'],$currentPage,$pageSize);?>
</div>
</div>
</div>
<script type="text/javascript" src="js/easydialog.min.js"></script>
<script type="text/javascript" src="js/placeholder.min.js"></script>
<script type="text/javascript" src="js/prod_pub.js"></script>
<script type="text/javascript" src="js/prod_manage.js"></script>